# The input part to spites grew so massive
# it deserved its own file

from spites_util import *
from spites_config import *


def get_input(Game):
    # takes input and updates the speed
    # of the player block
    

    if not MOUSE_GUIDANCE_MODE:
        
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    sys.exit()
                if event.key == pygame.K_p:
                    Game.brake = True
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_p:
                    Game.brake = False
            

            # keypress events
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_DOWN or event.key == pygame.K_s:
                    Game.down = True
                        
                if event.key == pygame.K_UP or event.key == pygame.K_w:
                    Game.up = True
                        
                if event.key == pygame.K_LEFT or event.key == pygame.K_a:
                    Game.left = True
                                    
                if event.key == pygame.K_RIGHT or event.key == pygame.K_d:
                    Game.right = True
                        
                    
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_DOWN or event.key == pygame.K_s:
                    Game.down = False
                        
                if event.key == pygame.K_UP or event.key == pygame.K_w:
                    Game.up = False
                        
                if event.key == pygame.K_LEFT or event.key == pygame.K_a:
                    Game.left = False
                        
                if event.key == pygame.K_RIGHT or event.key == pygame.K_d:
                    Game.right = False
                    
                if event.key == pygame.K_p:
                    Game.brake = False
    else:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    sys.exit()
                if event.key == pygame.K_p:
                    Game.brake = True
            if event.type == pygame.KEYUP:
                if event.key == pygame.K_p:
                    Game.brake = False
        mouse_x, mouse_y = mouse_position = pygame.mouse.get_pos()
        pX, pY = Game.player.rect.x, Game.player.rect.y
        Game.down, Game.up, Game.left, Game.right = False, False, False, False

        Game.player_speed[0] += (mouse_x - pX) * PLAYER_ACCELERATION
        Game.player_speed[1] += (mouse_y - pY) * PLAYER_ACCELERATION
    
    # adds to speed if needed
    if Game.brake:
        for i in range(5):
            Game.player1_speed[0] = P.block_deceleration(Game.player1_speed[0])
            Game.player1_speed[1] = P.block_deceleration(Game.player1_speed[1])
                
    if Game.up:
        Game.player1_speed[1] -= 150*PLAYER_ACCELERATION
    else :
        Game.player1_speed[1] = P.block_deceleration(Game.player1_speed[1])
        
    if Game.down:
        Game.player1_speed[1] += 150*PLAYER_ACCELERATION
    else :
        Game.player1_speed[1] = P.block_deceleration(Game.player1_speed[1])
            
    if Game.right:
        Game.player1_speed[0] += 150*PLAYER_ACCELERATION
    else :
        Game.player1_speed[0] = P.block_deceleration(Game.player1_speed[0])
    if Game.left:
        Game.player1_speed[0] -= 150*PLAYER_ACCELERATION
    else :
        Game.player1_speed[0] = P.block_deceleration(Game.player1_speed[0])
